home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Control del ratón / CheckerWithChildren / CheckerWithChildren.cs < prev    next >
Encoding:
Text File  |  2002-04-18  |  1.5 KB  |  51 lines

  1. //--------------------------------------------------
  2. // CheckerWithChildren.cs ⌐ 2001 by Charles Petzold
  3. //--------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class CheckerWithChildren: Form
  9. {
  10.      protected const int       xNum = 5;
  11.      protected const int       yNum = 4;
  12.      protected CheckerChild[,] acntlChild;
  13.  
  14.      public static void Main()
  15.      {
  16.           Application.Run(new CheckerWithChildren());
  17.      }
  18.      public CheckerWithChildren()
  19.      {
  20.           Text = "Marcador con secundarios";
  21.           BackColor = SystemColors.Window;
  22.           ForeColor = SystemColors.WindowText;
  23.           CreateChildren();
  24.  
  25.          OnResize(EventArgs.Empty);
  26.      }
  27.      protected virtual void CreateChildren()
  28.      {
  29.           acntlChild = new CheckerChild[yNum, xNum];
  30.  
  31.           for (int y = 0; y < yNum; y++)
  32.           for (int x = 0; x < xNum; x++)
  33.           {
  34.                acntlChild[y, x] = new CheckerChild();
  35.                acntlChild[y, x].Parent = this;
  36.           }
  37.      }
  38.      protected override void OnResize(EventArgs ea)
  39.      {
  40.           int cxBlock = ClientSize.Width / xNum;
  41.           int cyBlock = ClientSize.Height / yNum;
  42.  
  43.           for (int y = 0; y < yNum; y++)
  44.           for (int x = 0; x < xNum; x++)
  45.           {
  46.                acntlChild[y, x].Location = new Point(x*cxBlock, y*cyBlock);
  47.                acntlChild[y, x].Size     = new Size(cxBlock, cyBlock);
  48.           }
  49.      }
  50. }
  51.